<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


//做上传头像功能，如果上传了头像就用上传的头像，如果没有上传，则使用默认头像
function head($uid){
    $diskpath = ROOT_PATH . 'public' . DS . 'uploads' . DS . "head/{$uid}.jpg";
    //判断文件是否存在
    if(!file_exists($diskpath)){
        $uid = 'default';
    }

    $url = config('view_replace_str.__PUBLIC__');
    return $url."/uploads/head/{$uid}.jpg";
}
//做商品添加功能，对html编辑器图片上传的访问地址的处理
function up_url($filepath){
    //直接输入配置文件的值，$url的值和模板变量的值__PUBLIC__一致
    $url = config('view_replace_str.__PUBLIC__');
    return $url."/uploads/".$filepath;
}

//略缩图的访问地址
function thumb_url($filepath){
    //获取文件的后缀名
    $ext = pathinfo($filepath,PATHINFO_EXTENSION); 
    $url = up_url($filepath);
    return $url.".".$ext;
}